package test;

import java.util.*;

public class Solution1 {
    public int[] findNotBlocked(int[] speed) {
        int last = speed.length - 1;
        List<Integer> result = new ArrayList<>();
        result.add(last);
        int currentSpeed = speed[last];
        for (int i = last - 1; i >= 0; i--) {
            if (speed[i] > currentSpeed) {
                continue;
            }
            result.add(i);
            currentSpeed = speed[i];
        }
        Collections.sort(result);
        int[] ret = new int[result.size()];
        int i = 0;
        for (int index : result) {
            ret[i++] = index;
        }
        return ret;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1().findNotBlocked(new int[]{1,1,1}));
    }
}
